#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAXN = 30010;
int nums[MAXN];
int main(){
	int n,m;
	cin >> n >> m;
	int a, b;
	memset(nums, 0, sizeof(nums));
	for(int i = 0; i < n; i++){
		cin >> a >> b;
		nums[b] = a;
	}
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		nums[b] += a;
	}
	bool found = false;
	for(int i = 0; i < MAXN; i++){
		if(nums[i] != 0){
			if(found){
				if(nums[i] > 0)
					cout << "+";
			}
			if(nums[i] == -1)
				cout<<"-";
			else if(nums[i] != 1)
				cout<<nums[i];
			found = true;
			if(i == 1)
				cout<<"x";
			else if(i != 0)
				cout <<"x^"<<i;
		}
	}
	if(!found)
		cout << 0;
	return 0;
}

